<?php
class innerfadeWidget extends CWidget
{
	public $clientScript;
	
	public $baseUrl;
	public $Jscripts = array('jquery.innerfade.js');
	public $Cssscript = '';
	
	public $id = '.fade';
	
	public $options = "animationtype: 'slide',	speed: 'slow',	timeout: 2000,	type: 'random',	containerheight: '1em'";	//transition:"none", width:"75%", height:"75%"

   /**
    * Publishes the assets
    */
   public function publishAssets()
   {
      $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'assets';
 
      $this->baseUrl = Yii::app()->getAssetManager()->publish($dir);
   }
   
   /**
    * Registers the external javascript files
    */
   public function registerClientScripts()
   {
      if ($this->baseUrl === '')
         throw new CException('Can not find the base folder');

      $this->clientScript = Yii::app()->getClientScript();

      $this->clientScript->registerCoreScript('jquery');
      foreach ($this->Jscripts as $script)
      {
       $this->clientScript->registerScriptFile($this->baseUrl.'/js/'.$script,CClientScript::POS_END);     	
      }


      
      $this->clientScript->registerCssFile($this->baseUrl.'/css/'.$this->Cssscript);
   }
   
   public function registerScript()
   {
   		$script = <<<SCRIPT
   			
   		$('$this->id').innerfade({{$this->options}});
   		
   		
SCRIPT;
		Yii::app()->getClientScript()->registerScript('ext-box-colorbox-'.$this->id,$script,CClientScript::POS_READY);
   }
   

	public function run()
	{
		$this->publishAssets();
		$this->registerClientScripts();
		$this->registerScript();
//		$this->render('test');	
	}

}
?>